package com.jarveis.frame.lang;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;

import com.jarveis.frame.bean.BeanUtil;

/**
 * 对象工具类
 * 
 * @author liuguojun
 * 
 */
public class ObjectUtil {

	/**
	 * 验证对象是否为null
	 * <pre>
	 * Object object1;
	 * ObjectUtil.isNull(object1) = ture;
	 * 
	 * Object object2 = new Object();
	 * ObjectUtil.isNull(object1) = false;
	 * </pre>
	 * 
	 * @param object
	 * @return boolean
	 */
	public static boolean isNull(Object object) {
		return (object == null);
	}
	
	/**
	 * 验证对象属性是否初始化
	 * 
	 * @param object
	 * @return boolean
	 */
	public static boolean checkPropertyInit(Serializable s) {
		List<Field> fields = BeanUtil.getFields(s.getClass());
		for (Iterator<Field> fit = fields.iterator(); fit.hasNext();) {
			String fieldName = fit.next().getName();
			Object value = BeanUtil.getFieldValue(s, fieldName);
			if(!isNull(value)){
				return false;
			}
		}
		
		return true;
	}
}
